/* ========================================================================	*/
/* Project       : -                                                        */
/* Module        : ISO8583                                                  */
/* Creation Date : 08/12/2004                                               */
/* Author        : M. GATESOUPE                                             */
/* Description   : This module contains the interface with                  */
/*                 the ISO8583 communication component                      */
/* ========================================================================	*/
/* SAGEM Monetel                                                            */
/* 1 rue Claude Chappe - BP 346                                             */
/* 07503 Guilherand-Granges                                                 */
/* ========================================================================	*/
/* REVISION HISTORY                                                         */
/* ========================================================================	*/
/* Date          :                                                          */
/* Author        :                                                          */
/* Description   :                                                          */
/* ========================================================================	*/

#ifndef _ISO8583_H_
#define _ISO8583_H_

//// Macros & preprocessor definitions //////////////////////////

// ISO8583 fields default tags
#define	TAG_ISO8583_FIELDS						0x9F8A00
#define	TAG_ISO8583_DEFAULT_FIELD(nField)		(0x9F8A00 + nField)

// ISO8583 specific tags
#define	TAG_ISO8583_MESSAGE_HEADER				0x9F8A81
#define	TAG_ISO8583_MESSAGE_TRAILER				0x9F8A82

#define	TAG_ISO8583_93_MSG_REASON_CODE			0x9F8A83
#define	TAG_ISO8583_93_ACTION_CODE				0x9F8A84

#define	TAG_ISO8583_APPLI_STATUS_CODE			0x9F8A85

// Configuration tags
#define TAG_ISO8583_T_TIMEOUT					1
#define TAG_ISO8583_L_TIMEOUT					4
#define ISO8583_DEFAULT_TIMEOUT					3000

#define TAG_ISO8583_T_RESEND					2
#define TAG_ISO8583_L_RESEND					1
#define ISO8583_DEFAULT_MAX_RESEND				3

#define TAG_ISO8583_T_DESCRIPTOR_ID				3
#define TAG_ISO8583_L_DESCRIPTOR_ID				1

#define TAG_ISO8583_T_FILENAME					4
#define TAG_ISO8583_L_MAX_FILENAME				16

#define TAG_ISO8583_T_PATH						5
#define TAG_ISO8583_L_MAX_PATH					16

#define TAG_ISO8583_T_FRAME_SIZE_TYPE				6
#define TAG_ISO8583_L_FRAME_SIZE_TYPE				1
#define TAG_ISO8583_V_FRAME_SIZE_TYPE_NONE			0
#define TAG_ISO8583_V_FRAME_SIZE_TYPE_LSBF			1
#define TAG_ISO8583_V_FRAME_SIZE_TYPE_MSBF			2
#define TAG_ISO8583_V_FRAME_SIZE_TYPE_LSBF_HEADER	3
#define TAG_ISO8583_V_FRAME_SIZE_TYPE_MSBF_HEADER	4

#define TAG_ISO8583_T_FRAME_SIZE_LENGTH			7
#define TAG_ISO8583_L_FRAME_SIZE_LENGTH			1
#define TAG_ISO8583_V_FRAME_SIZE_LENGTH_DEFAULT	4

// Configuration tags
#define TAG_ISO8583_T_TIMEOUT_2					8
#define TAG_ISO8583_L_TIMEOUT_2					4
#define ISO8583_DEFAULT_TIMEOUT_2				200

#define TAG_ISO8583_T_HOOK_APPLI_TYPE			12
#define TAG_ISO8583_L_HOOK_APPLI_TYPE			2

#define TAG_ISO8583_T_HOOK_SEND_SERVICE_ID		13
#define TAG_ISO8583_L_HOOK_SEND_SERVICE_ID		2

#define TAG_ISO8583_T_HOOK_RECEIVE_SERVICE_ID	14
#define TAG_ISO8583_L_HOOK_RECEIVE_SERVICE_ID	2

// Protocol types
#define COMM_PROTOCOL_TYPE_ISO8583_87			10
#define COMM_PROTOCOL_TYPE_ISO8583_93			11

// Maximum frame size allowed in hook functions
#define ISO8583_HOOK_MAX_FRAME_SIZE				(4096)

// Choose RAW mode or not during configuration
#define TAG_ISO8583_T_RAW_MODE                  20
#define TAG_ISO8583_L_RAW_MODE                  1
#define TAG_ISO8583_V_RAW_MODE_NOT_USED         0
#define TAG_ISO8583_V_RAW_MODE_USED             1

//// Types //////////////////////////////////////////////////////

typedef struct
{
	// "Application Type" of the called application
	unsigned short m_usAppliType;
	// "Service ID" called
	unsigned short m_usService;

	// Status to return to the application
	int m_nAppliStatus;
	// Status to return to the ISO8583 component (decode or not the received frame, ...)
	int m_nIsoStatus;

	// Size of the frame
	int m_nFrameSize;
	// Frame
	unsigned char m_Frame[ISO8583_HOOK_MAX_FRAME_SIZE];
} T_ISO8583_HOOK_PARAMS;

typedef struct
{

  unsigned short mti;					/**< Message Type Identifier */
  unsigned short service;		      	/**< Service to be called */
  int length;							/**< Length of the raw message the message to send (96) */ 
  Byte rawMessage[4096];  	/**< Raw Message to send : ISO_MESSAGE_SIZE =4096 */
  _DEL_  DEL;					 		/**< Input / Output DEL.	*/
} StructForRawMessage; 

//// Global variables ///////////////////////////////////////////

//// Functions //////////////////////////////////////////////////

#endif // _ISO8583_H_
